<style scoped lang="less">
	.top {
		display: flex;
		justify-content: space-between;
		align-items: center;

		p {
			font-size: 21px;
			font-weight: 600;
		}

		span {
			font-size: 17px;
		}
	}

	.content {
		width: 100%;
		margin-top: 3%;
		// border:1px solid red;
		display: flex;
		flex-wrap: wrap;

		.box {
			width: 45%;
			height: 5vh;
			// border:1px solid red;
			display: flex;
			align-items: center;
			box-sizing: border-box;
			padding: 0 3%;
			margin-top: 3%;

			span {
				font-size: 18px;
				font-weight: 500;
			}

			.el-input {
				width: 300px;
				margin-right: 10px;
				border: none;
			}
			.el-date-picker{
				width: 300px;
			}
		}
	}
	.el-button{
		float:right;
		margin-right: -70%;
	}
	
</style>
<template>
	<div class="top">
		<p>换课信息</p>
		<el-button type="success" @click="applyFn">完成</el-button>
		<span @click="back">返回</span>
	</div>
	<div class="content">
		<div class="box">
			<span>申请老师&nbsp;&nbsp;&nbsp;：</span>
			<el-input placeholder="请输入申请姓名" v-model="appUserName" disabled></el-input>
		</div>
		<div class="box">
			<span>调课时间&nbsp;&nbsp;&nbsp;：</span>
			<el-date-picker
			        v-model="applyData.newTime"
			        type="date"
			        placeholder="Pick a day"
			        :size="size"
						value-format="YYYY-MM-DD"
			      />
			   
			<!-- <el-input placeholder="请输入时间" v-model="applyData.newTime"></el-input> -->
		</div>
		<div class="box">
			<span>申请课程&nbsp;&nbsp;&nbsp;：</span>
			<el-select v-model="applyData.oldSubId" placeholder="请选择" style="width: 300px">
				<el-option v-for="item in classArr" :key="item.subId" :label="item.subName" :value="item.subId" />
			</el-select>
		</div>
		<div class="box">
			<span>审批人&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;：</span>
			<!-- {{examArr}} -->
			<el-select v-model="applyData.userId" placeholder="请选择" style="width: 300px">
				<el-option v-for="item in examArr" :key="item.userId" :label="item.userName" :value="item.userId" />
			</el-select>
		</div>
		<div class="box">
			<span>申请班级&nbsp;&nbsp;&nbsp;：</span>
			<el-select v-model="applyData.oldClazzId" placeholder="请选择" style="width: 300px">
				<el-option v-for="item in AllClass" :key="item.clazzId" :label="item.clazzName" :value="item.clazzId" />
			</el-select>
		</div>
		<div class="box">
			<span>指向老师&nbsp;&nbsp;&nbsp;：</span>
			<el-select v-model="applyData.newTeaId" placeholder="请选择" style="width: 300px">
				<el-option v-for="item in teaArr" :key="item.userId" :label="item.teaName" :value="item.userId" />
			</el-select>
		</div>
		<div class="box">
			<span>原上课时间：</span>
			<el-date-picker
			        v-model="applyData.oldTime"
			        type="date"
			        placeholder="请选择原上课时间"
					value-format="YYYY-MM-DD"
					
			      />
				  
			<!-- <el-input placeholder="请输入时间" v-model="applyData.oldTime"></el-input> -->
		</div>
		<div class="box">
			<span>指向课程&nbsp;&nbsp;&nbsp;：</span>
			<el-select v-model="applyData.newSubId" placeholder="请选择" style="width: 300px">
				<el-option v-for="item in classArr" :key="item.subId" :label="item.subName" :value="item.subId" />
			</el-select>
		</div>
		<!-- <div class="box">
			<span>申请日期&nbsp;&nbsp;&nbsp;：</span>
			<el-input placeholder="请输入时间" v-model="applyData.newTime" disabled></el-input>
		</div> -->
		<div class="box">
			<span>指向班级&nbsp;&nbsp;&nbsp;：</span>
			<el-select v-model="applyData.newClazzId" placeholder="请选择" style="width: 300px">
				<el-option v-for="item in AllClass" :key="item.clazzId" :label="item.clazzName" :value="item.clazzId" />
			</el-select>
		</div>
	</div>
	
</template>

<script setup lang="ts">
	import { ref,reactive } from 'vue'
	import { useRoute, useRouter } from 'vue-router';
	import { changeApply, classList, courseList, examList, teachers } from '@/api/gh';
	let fristTime = ref("")
	const getFristTime=()=>{
		console.log(fristTime.value)
	}
	let route = useRoute();
	let router = useRouter()
	let classArr = ref([])//所有课程
	let AllClass : any = ref([])//所有班级
	let examArr:any  = ref([])//审批人列表
	let appUserName = ref(sessionStorage.getItem("userName"))//申请人姓名
	let appUserId = sessionStorage.getItem("userId")
	let teaArr:any = ref([])//老师列表
	let applyData = reactive({
		oldTeaId:appUserId,	//是	Int	申请老师id
		oldClazzId:"",	//是	Int	申请课程id
		oldTime	:"",//是	String	原上课时间
		oldSubId:"",//	是	Int	申请课程id
		newTeaId:"",//	是	Int	指向老师id
		newTime:"",	//是	String	指向时间
		newClazzId:"",//	是	Int	指向班级id
		newSubId:"",	//是	Int	指向课程id
		userId:"",	//是	Int	审批人
	})
	//申请
	const applyFn= async ()=>{
		let data = applyData;
		
		let flag = true
		for(let key in applyData){
			if(applyData[key]==""){
				flag = false
			}
			if(typeof applyData[key] == "number"){
				 applyData[key]=applyData[key]+""
			}
			
		}
		// console.log("data",data)
		if(flag){
			let res = await changeApply(applyData)
			applyData ={
				oldTeaId:appUserId,	//是	Int	申请老师id
				oldClazzId:"",	//是	Int	申请课程id
				oldTime	:"",//是	String	原上课时间
				oldSubId:"",//	是	Int	申请课程id
				newTeaId:"",//	是	Int	指向老师id
				newTime:"",	//是	String	指向时间
				newClazzId:"",//	是	Int	指向班级id
				newSubId:"",	//是	Int	指向课程id
				userId:"",
				}
				router.push({
					path:"/changecourses"
				})
			// console.log("applyFn",res)
		}
		
		
	}
	const options = [
		{
			value: 'Option1',
			label: 'Option1',
		},
		{
			value: 'Option2',
			label: 'Option2',
		},

	]
	//返回
	const back = () => {
		router.push({

			path: "/changecourses"
		})
	}
	//获取课程列表
	let getclassList = async () => {
		let res = await courseList()
		// console.log("课程列表classArr",res)
		classArr.value = res
	}
	getclassList()
	//获取所有班级
	let getAllClass = async () => {
		let res = await classList();
		console.log("所有班级",res)
		AllClass.value = res
	}
	getAllClass()
	//获取审批人列表
	let getExamList = async () => {
		let res = await examList({
			userId: sessionStorage.getItem("userId")
		})
		console.log("审批人列表examArr",res)
		// Object.assign(examArr,res)
		examArr.value = res
	}
	getExamList()
	//获取所有老师
	const getTea = async()=>{
		// console.log("12321312")
		let res = await teachers({
			pageIndex:1,
			pageSize:50
		})
		// Object.assign(teaArr.value,res)
		teaArr.value = res.Tealist
		// console.log("教师",res)
	}
	getTea()

	//格式化日期
	const getNowDate = () => {
	  var date = new Date();
	  var sign2 = ":";
	  var year = date.getFullYear() // 年
	  var month = date.getMonth() + 1; // 月
	  var day = date.getDate(); // 日
	  var hour = date.getHours(); // 时
	  var minutes = date.getMinutes(); // 分
	  var seconds = date.getSeconds() //秒
	  var weekArr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期天'];
	  var week = weekArr[date.getDay()];
	  // 给一位数的数据前面加 “0”
	  if (month >= 1 && month <= 9) {
	    month = "0" + month;
	  }
	  if (day >= 0 && day <= 9) {
	    day = "0" + day;
	  }
	  if (hour >= 0 && hour <= 9) {
	    hour = "0" + hour;
	  }
	  if (minutes >= 0 && minutes <= 9) {
	    minutes = "0" + minutes;
	  }
	  if (seconds >= 0 && seconds <= 9) {
	    seconds = "0" + seconds;
	  }
	  return year + "-" + month + "-" + day + " " + hour + sign2 + minutes + sign2 + seconds;
	}
	applyData.newTime = getNowDate()
</script>